/**
 * 
 */
package net.jbaez.code;

import java.lang.reflect.Modifier;
import java.util.ArrayList;

/*
 * Copyright 2008 DynamiCode
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
/**
 * Modificadores que pueden tener los elementos de tipo IMember
 */
public enum JModifier {

    STATIC(Modifier.STATIC, Modifier.toString(Modifier.STATIC)), SYNCHRONIZED(
	    Modifier.SYNCHRONIZED, Modifier.toString(Modifier.SYNCHRONIZED)), VOLATILE(
	    Modifier.VOLATILE, Modifier.toString(Modifier.VOLATILE)), FINAL(
	    Modifier.FINAL, Modifier.toString(Modifier.FINAL)), NATIVE(
	    Modifier.NATIVE, Modifier.toString(Modifier.NATIVE)), ABSTRACT(
	    Modifier.ABSTRACT, Modifier.toString(Modifier.ABSTRACT)), STRICT(
	    Modifier.STRICT, Modifier.toString(Modifier.STRICT)), TRANSIENT(
	    Modifier.TRANSIENT, Modifier.toString(Modifier.TRANSIENT)), INTERFACE(
	    Modifier.INTERFACE, Modifier.toString(Modifier.INTERFACE));

    // Valor numerico
    private int intValue;
    // Representacion texto
    private String code;

    JModifier(int intValue, String code) {
	this.intValue = intValue;
	this.code = code;
    }

    /**
     * @return the intValue
     */
    public int getIntValue() {
	return intValue;
    }

   /**
    * Retorna un arreglo con todos los valores
    * modificadores que representa el valor pasado
    * como parametro
    * @param intValue Valor a transformar
    * @return Arreglo con los modificadores o <code>null</code>
    * si el valor pasado no coincide con ningun modificador
    */
    public static JModifier[] getModifier(int intValue) {
	//Lista donde colocar los valores
	ArrayList<JModifier> list = new ArrayList<JModifier>(1);
	
	if(Modifier.isStatic(intValue)) list.add(STATIC);
	if(Modifier.isStrict(intValue)) list.add(STRICT);
	if(Modifier.isAbstract(intValue)) list.add(ABSTRACT);
	if(Modifier.isFinal(intValue)) list.add(FINAL);
	if(Modifier.isInterface(intValue)) list.add(INTERFACE);
	if(Modifier.isNative(intValue)) list.add(NATIVE);
	if(Modifier.isSynchronized(intValue)) list.add(SYNCHRONIZED);
	if(Modifier.isTransient(intValue)) list.add(TRANSIENT);
	if(Modifier.isVolatile(intValue)) list.add(VOLATILE);
	
	if(list.isEmpty()) return null;
	return (JModifier[]) list.toArray(new JModifier[]{});
    }

    public String toString() {
	return code;
    }
}
